/*-----------------------------------------------------------------------------
		   Licensed to the Apache Software Foundation (ASF) under one
           or more contributor license agreements.  See the NOTICE file
           distributed with this work for additional information
           regarding copyright ownership.  The ASF licenses this file
           to you under the Apache License, Version 2.0 (the
           "License"); you may not use this file except in compliance
           with the License.  You may obtain a copy of the License at

             http://www.apache.org/licenses/LICENSE-2.0

           Unless required by applicable law or agreed to in writing,
           software distributed under the License is distributed on an
           "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
           KIND, either express or implied.  See the License for the
           specific language governing permissions and limitations
           under the License.  
-----------------------------------------------------------------------------*/

package data;

/**
 * This class represents a source method which is composed of many fields. There
 * are simple metrics that can be applied to these objects. 
 * <p>They are the base of the hierarchy structure {@link SFile} > 
 * {@link SFolder} > {@link SMethod}
 * <p> SLOC = Source Lines of Code <p> CC = Cyclomatic Complexity
 * 
 * @author Kevin.J.Jalbert
 */
public class SMethod{

	private String signature = ""; // Method signature 
	private int sourceLines = 0; // Number of SLOC excluding comments and whitespace 
	private int nestedLevel = 0; // TODO This hasn't been used yet
	private float forCount = 0;
	private float whileCount = 0;
	private float ifCount = 0;
	private float elseIfCount = 0;
	private float switchCount = 0;
	private float caseCount = 0;

	/**
	 * Instantiates a new {@link SMethod} with the data on the method.
	 * 
	 * @param forCount the for count
	 * @param whileCount the while count
	 * @param ifCount the if count
	 * @param elseIfCount the else if count
	 * @param switchCount the switch count
	 * @param caseCount the case count
	 * @param sourceLines the source lines
	 * @param nestedLevel the nested level
	 * @param signature the signature
	 */
	public SMethod(float forCount, float whileCount, float ifCount, float elseIfCount, float switchCount, 
			float caseCount, int sourceLines, int nestedLevel, String signature){

		this.forCount = forCount;
		this.whileCount = whileCount;
		this.ifCount = ifCount;
		this.elseIfCount = elseIfCount;
		this.switchCount = switchCount;
		this.caseCount = caseCount;
		this.sourceLines = sourceLines;
		this.nestedLevel = nestedLevel;		
		this.signature = signature;
	}

	/**
	 * Gets the source lines.
	 * 
	 * @return sourceLines the source lines
	 */
	public int getSourceLines() {
		return sourceLines;
	}

	/**
	 * Gets the nested level.
	 * 
	 * @return nestedLevel the nested level
	 */
	public float getNestedLevel() {
		return nestedLevel;
	}

	/**
	 * Gets the method signature.
	 * 
	 * @return signature the method signature
	 */
	public String getSignature() {
		return signature;
	}

	/**
	 * Gets the cyclomatic complexity.
	 * 
	 * @return the cyclomatic complexity
	 */
	public int getCyclo() {
		int cycloCount = (int) (forCount + whileCount + ifCount + elseIfCount + switchCount + caseCount + 1);
		return cycloCount;
	}

	/**
	 * Gets the SLOC per CC.
	 * 
	 * @return the SLOC per CC
	 */
	public float getSLOCPerCC(){

		float sLOCPerCC = 0;

		// If there is no CC then assign it -1
		if (getCyclo() == 0){
			sLOCPerCC = -1;
		}
		else{
			sLOCPerCC = (getSourceLines()/getCyclo());
		}

		return sLOCPerCC;
	}	
}